#include "TCPServer.hpp"
#include "ServerCal.hpp"

#include <iostream>

void Usage(char *str)
{
    std::cout << std::endl
              << "Usabe: " << str << " + Server_port" << std::endl
              << std::endl;
}


int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        return -5;
    }

    //这里不需要调用htons，不然两次转换会导致端口号错误
    //因为小端机上假设端口号是 0x1234 调用一次htons就会转换成0x3412
    //再调用一次htons，它识别到时小端机，又换转换成0x1234
    //uint16_t server_port = htons(std::stoi(argv[1]));
    
    uint16_t server_port = std::stoi(argv[1]);
    ServerCal ser;
    TcpServer tcp(server_port, std::bind(&ServerCal::Calculate, ser, std::placeholders::_1));
    tcp.Init();
    tcp.Start();

    return 0;
}
